#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <iostream>
#include "mock_server.h"
#include "safe_map.h"
#include <sstream>
#include <netinet/in.h>
#include <vector>
#include "ap/signal_id.h"
#include "vp/VGM_TX.h"
#include "vp/VGM_RX.h"
#include "vp/SignalServiceId.h"
#include "src/validate.h"
#include "ap/IPCPSignalManager.h"
#include "vp/pafunctype.h"
#include "android/log.h"
#include "vp/CEM_TX.h"
#include "vp/HUD_RX.h"
#include "cp/Normal.h"
#include "cp/CP_ServiceId.h"
#include "ap/NetAPCP.h"
#include "transfer/SafeQueue.h"

#define MAX_PAYLOAD  1450

#define LOCAL_SERVER_IP        "127.0.0.1"
#define LOCAL_SERVER_PORT        50500

#define PEER_DEMO_CLIENT_IP        "127.0.0.1"
#define PEER_DEMO_CLIENT_PORT        8888

#define PEER_HAL_CLIENT_IP        "127.0.0.1"
#define PEER_HAL_CLIENT_PORT        50335
#define PEER_HAL_DIM_CLIENT_PORT        50435

#define CP_SERVICE_NORMAL_PORT 50340
#define CP_SERVICE_TIME_PORT 50601
#define CP_SERVICE_AVAS_PORT 50602

#define SETREQUEST_CBK_MSG "set property success."

using namespace std;

void received_cb(ipcp_packet_t *packet, ipcp_peer_t peer);

void error_cb(ipcp_packet_t *ipcp_packet, ipcp_stack_err_t error);

void initNotifyDataMap(int serviceId);

string getIpcpKey(IpcpValue *ipValue);

string getCallbackKey(IpcpValue *ipValue);

void notifyCallbacks(IpcpValue *ipValue);

void recordCallbacks(IpcpValue *ipValue, ipcp_peer_t peer);

void syncToHal(IpcpValue *ipValue);

void recordSignalStatusInfo(IpcpValue *ipValue);

std::map<string, CbkValue *> callbackMap;

MOCK::SafeMap<string, SignalStatusInfo *> signalStatusInfoMap;

MOCK::SafeMap<int, void *> notifyDataMap;

ipcp_packet_t *upper_packet = NULL;

std::vector<ipcp_transport_conf_t> mTransportConfigs;
std::vector<ipcp_transport_conf_t> mTransportConfigsForDim;

static ecarx::transfer::utils::ConcurrentQueue<IpcpValue*> mIpcpQueue;
static ecarx::transfer::utils::BatchingConsumer<IpcpValue*> mBatchingConsumer;
static ipcp_peer_t udp_hal_peer = {
        .sk_type = IPCP_TRANSPORT_UDP,
        .peer_ip = PEER_HAL_CLIENT_IP,
        .peer_port = PEER_HAL_CLIENT_PORT,
};

static ipcp_peer_t udp_hal_peer_dim = {
        .sk_type = IPCP_TRANSPORT_UDP,
        .peer_ip = PEER_HAL_CLIENT_IP,
        .peer_port = PEER_HAL_DIM_CLIENT_PORT,
};

ipcp_callbacks_t callbacks = {
        .ipcp_received_cb = received_cb,
        .error_cb = error_cb,
};

void common_log(const char *format, ...) {
    char msg[1024];

    va_list ap;
    va_start(ap, format);
    vsnprintf(msg, sizeof(msg), format, ap);
    va_end(ap);

    __android_log_print(ANDROID_LOG_DEBUG, "mockserver", "jdbg mockserver %s\n", msg);
    printf("%s jdbg mockserver %s\n", "mockserver",msg);
}

string getIpcpKey(IpcpValue* ipValue) {
    stringstream ss;
    ss << ipValue->service_id << ':' << ipValue->oper_id;
    string ipcpKey = ss.str();
    return ipcpKey;
}

string getCallbackKey(IpcpValue *ipValue) {
    stringstream ss;
    ss << ipValue->peer_ip << ':' << ipValue->peer_port << ':' << ipValue->service_id << ':'
       << ipValue->oper_id;
    string cbkKey = ss.str();
    return cbkKey;
}

void received_cb(ipcp_packet_t * packet, ipcp_peer_t peer) {
    std::cout << "\n received_cb>>>>>>>" << peer.peer_ip << ": peer_ip=" << peer.peer_ip
              << ", peer_port=" << peer.peer_port << std::endl;
    size_t payload_len = packet->header.length - PACKET_HEADER_OFFSET;
    if (payload_len <= 0 || packet->header.op_type > 0x5 )
        return;
    IpcpValue *ipValue = (IpcpValue *) malloc(sizeof(IpcpValue));
    ipValue->service_id = packet->header.service_id;
    ipValue->oper_id = packet->header.operation_id;
    ipValue->senderHandleId = packet->header.senderHandleId;
    ipValue->oper_type = packet->header.op_type;
    ipValue->payload_type = packet->header.payload_type;
    memset(ipValue->peer_ip, 0, sizeof(ipValue->peer_ip));
    strcpy(ipValue->peer_ip, peer.peer_ip); // service ip
    ipValue->peer_port = peer.peer_port;

    ipValue->payload_len = payload_len;
    ipValue->payload = (void *) malloc(ipValue->payload_len);
    memcpy(ipValue->payload, packet->payload, ipValue->payload_len);
    std::cout << "service_id=" << ipValue->service_id << ",oper_id=" <<ipValue->oper_id <<  ",oper_type="<< static_cast<int>(ipValue->oper_type) << ",payload_type="  << static_cast<int>(ipValue->payload_type)
              <<  ",payload_len=" << ipValue->payload_len << std::endl;
    common_log("received_cb peerip:%s, port:%u, svcid:%d,opid:%d, optype:%d,payloadtype:%d, len:%d", peer.peer_ip, (uint16_t)peer.peer_port,
                ipValue->service_id,ipValue->oper_id,
               static_cast<int>(ipValue->oper_type), static_cast<int>(ipValue->payload_type),ipValue->payload_len);
    mIpcpQueue.push(std::move(ipValue));
}

void readThread(IpcpValue* ipValue) {
    string ipcpKey = getIpcpKey(ipValue);
    common_log("readThread>>>>>>>>>>>>>>>>>>serviceid:%u, opid:%u,optype:%u,len:%u,port:%u",
               ipValue->service_id, ipValue->oper_id, ipValue->oper_type,ipValue->payload_len, ipValue->peer_port);
    switch (ipValue->oper_type) {
            // set no return
        case IPCP_OPERATION_SETREQUEST_NORETURN: {
            syncToHal(ipValue);
            if (strcmp(ipValue->peer_ip, PEER_HAL_CLIENT_IP) != 0 ||
                ipValue->peer_port != PEER_HAL_CLIENT_PORT) {
                //notifyCallbacks(ipValue);
            }
        }
            break;
            // callback
        case IPCP_OPERATION_NOTIFICATION: {
            // 给测试开的口子，可以模拟availability、status等信号信息的变化
            if (strcmp(ipValue->peer_ip, PEER_HAL_CLIENT_IP) != 0 ||
                ipValue->peer_port != PEER_HAL_CLIENT_PORT) {

                ipcp_packet_t *packet = build_ipcp_packet(ipValue->service_id, ipValue->oper_id,
                                                          IPCP_OPERATION_NOTIFICATION,
                                                          ipValue->payload_type, ipValue->payload,
                                                          ipValue->payload_len);
                ipcp_stack_err_t error_code = ipcp_send(udp_hal_peer, packet);
                common_log(" mocktest request, synctoHal code:%d", error_code);
                std::cout<<"syncToHal for test, result code: " << error_code << "\n";
                if (error_code == STACK_SEND_MSG_SUCCESS) {
                    recordSignalStatusInfo(ipValue);
                }
            }

        }
            break;
        default:

            break;
    }
    if (ipValue->payload_len > 0){
        free(ipValue->payload);
        ipValue->payload = nullptr;
    }
    free(ipValue);
    ipValue = nullptr;
    common_log("readThread<<<<<<<<<<<<<<<<<<");
}

void recordSignalStatusInfo(IpcpValue *ipValue) {
    switch (ipValue->service_id) {
        case EcarXSignalServiceID::serviceID_AUDIORADIO: {
            OpAudioRadio_Notification data;
            constexpr int structLen = (int) sizeof(OpAudioRadio_Notification);
            int bufferLength = structLen;
            if (ipValue->payload_len < structLen) {
                bufferLength = ipValue->payload_len;
            }
            memcpy(&data, ipValue->payload, bufferLength);

            SignalStatusInfo *ssInfo = nullptr;
            signalStatusInfoMap.Find(getIpcpKey(ipValue), ssInfo);
            if (ssInfo == nullptr) {
                ssInfo = new SignalStatusInfo();
                signalStatusInfoMap.Insert(getIpcpKey(ipValue), ssInfo);
            }
            ssInfo->availability = ntohl(data.paarwarningvlo.availability);
            ssInfo->format = ntohl(data.paarwarningvlo.format);
            ssInfo->status = ntohl(data.paarwarningvlo.status);
        }
            break;
        case EcarXSignalServiceID::serviceID_VGM: {
            if (ipValue->oper_id == VGMNotificationOpID) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_VGM da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpVGM_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_VGM save OpVGM_Notification ");
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_CLIMATE: {
            std::cout << "EcarXSignalServiceID::serviceID_CLIMATE:" << ipValue->oper_id << "\n";
            if (ipValue->oper_id == cbclairctrloffOpID) {
                OpClimate_Notification data;
                constexpr int structLen = (int) sizeof(OpClimate_Notification);
                int bufferLength = structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(&data, ipValue->payload, bufferLength);

                void *da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    return;
                }
                OpClimate_Notification *notifyData = (OpClimate_Notification *) da;
                notifyData->paclairctrloff = data.paclairctrloff;
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_CARCONFIG: {
            if (ipValue->oper_id == 200) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_CARCONFIG da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpCARCONFIG_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < bufferLength) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da , ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_CARCONFIG save OpCARCONFIG_Notification ");
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_CARCONFIGTHOUSAND: {
            if (ipValue->oper_id == 200) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_CARCONFIGTHOUSAND da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpCARCONFIGTHOUSAND_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < bufferLength) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_CARCONFIGTHOUSAND save OpCARCONFIGTHOUSAND_Notification ");
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_VDDM: {
            if (ipValue->oper_id == VDDMNotificationOpID) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_VDDM da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpVDDM_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_VDDM save OpVDDM_Notification ");
            }
        }
            break;

        case EcarXSignalServiceID::serviceID_CEM: {
            if (ipValue->oper_id == CEMNotificationOpID) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_CEM da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpCEM_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_CEM save OpCEM_Notification ");
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_CDM: {
            if (ipValue->oper_id == CDMNotificationOpID) {
                void* da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_CDM da is nullptr, return");
                    return;
                }
                constexpr int structLen=(int)sizeof(OpCDM_Notification);
                int bufferLength=structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_CDM save OpCEM_Notification ");
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_ASDM: {
            if (ipValue->oper_id == ASDMNotificationOpID) {
                void *da;
                notifyDataMap.Find(ipValue->service_id, da);
                if (da == nullptr) {
                    common_log("recordSignalStatusInfo serviceID_ASDM da is nullptr, return");
                    return;
                }
                constexpr int structLen = (int) sizeof(OpASDM_Notification);
                int bufferLength = structLen;
                if (ipValue->payload_len < structLen) {
                    bufferLength = ipValue->payload_len;
                }
                memcpy(da, ipValue->payload, bufferLength);
                common_log("recordSignalStatusInfo serviceID_ASDM save OpASDM_Notification ");
            }
        }
            break;
    }
}

void recordCallbacks(IpcpValue *ipValue, ipcp_peer_t peer) {
    string cbkKey = getCallbackKey(ipValue);
    CbkValue *cbkValue = new CbkValue();
    cbkValue->ipcpValue = ipValue;
    cbkValue->sk_type = peer.sk_type;
    callbackMap.insert(std::make_pair(cbkKey, cbkValue));
}

void syncToHal(IpcpValue *ipValue) {
    bool needSyncToHal = true;
    uint8_t buffer[MAX_PAYLOAD] = {0};
    int buf_len=0;
    switch (ipValue->service_id)
    {

        case EcarXSignalServiceID::serviceID_AUDIORADIO:
        {
            OpCBARWarningVlo_SetRequestNoReturn arWarn;
            int structLen = sizeof(OpCBARWarningVlo_SetRequestNoReturn);
            int bufferLength = structLen;
            if (ipValue->payload_len < structLen) {
                bufferLength = ipValue->payload_len;
            }
            memcpy(&arWarn, ipValue->payload, bufferLength);
            PAIntFuncType paIntFuncType;
            if (strcmp(ipValue->peer_ip, PEER_HAL_CLIENT_IP) != 0 ||
                ipValue->peer_port != PEER_HAL_CLIENT_PORT) {
                paIntFuncType.data = ntohl(arWarn.value);
            } else {
                paIntFuncType.data = arWarn.value;
            }
            SignalStatusInfo *ssInfo = nullptr;
            if (signalStatusInfoMap.Find(getIpcpKey(ipValue), ssInfo)) {
                paIntFuncType.availability = ntohl(ssInfo->availability);
                paIntFuncType.format = ntohl(ssInfo->format);
                paIntFuncType.status = ntohl(ssInfo->status);
            } else {
                paIntFuncType.availability = ntohl(0);
                paIntFuncType.format = ntohl(0);
                paIntFuncType.status = ntohl(0);
            }

            _OpAudioRadio_Notification notification;
            notification.paarwarningvlo = paIntFuncType;
            memcpy(buffer, &notification, sizeof(_OpAudioRadio_Notification));
            buf_len = sizeof(_OpAudioRadio_Notification);
            common_log("syncToHal serviceID_AUDIORADIO data:%d", arWarn.value);
        }
            break;
        case EcarXSignalServiceID::serviceID_VGM: {
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_VGM data is nullptr");
                return;
            }
            needSyncToHal = false;
        }
            break;
        case EcarXSignalServiceID::serviceID_CLIMATE: {
            void *climateData;
            notifyDataMap.Find(ipValue->service_id, climateData);
            if (climateData == nullptr) {
                return;
            }
            OpClimate_Notification *notifyData = (OpClimate_Notification *) climateData;
            switch (ipValue->oper_id) {
                case cbclairctrloffOpID: {
                    OpCBCLAirCtrlOff_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLAirCtrlOff_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclairctrloff.availability = ntohl(1);
                    notifyData->paclairctrloff.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclsecrowonoffswithOpID: {
                    OpCBCLSecRowOnOffSwith_SetRequestNoReturn  data;
                    constexpr int structLen = (int) sizeof(OpCBCLSecRowOnOffSwith_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsecrowonoffswith.availability = ntohl(1);
                    notifyData->paclsecrowonoffswith.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclsyncOpID: {
                    OpCBCLSync_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLSync_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsync.availability = ntohl(1);
                    notifyData->paclsync.data = data.value;
                    std::cout << "data.value = " << data.value
                              << "  ntohl(data.value) = " << ntohl(data.value) << std::endl;
                }
                    break;
                case cbclacOpID: {
                    OpCBCLAC_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLAC_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclac.availability = ntohl(1);
                    notifyData->paclac.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclacOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclmaxacOpID: {
                    OpCBCLMaxAC_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLMaxAC_SetRequestNoReturn);
                    int bufferLength = structLen;

                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclmaxac.availability = ntohl(1);
                    notifyData->paclmaxac.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclmaxacOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclmaxdefrostOpID: {
                    OpCBCLMaxDefrost_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLMaxDefrost_SetRequestNoReturn);
                    int bufferLength = structLen;

                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclmaxdefrost.availability = ntohl(1);
                    notifyData->paclmaxdefrost.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclmaxdefrostOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclfrontdefrostOpID: {
                    OpCBCLFrontDefrost_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLFrontDefrost_SetRequestNoReturn);
                    int bufferLength = structLen;

                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclfrontdefrost.availability = ntohl(1);
                    notifyData->paclfrontdefrost.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclfrontdefrostOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclreardefrostOpID: {
                    OpCBCLRearDefrost_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLRearDefrost_SetRequestNoReturn);
                    int bufferLength = structLen;

                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclreardefrost.availability = ntohl(1);
                    notifyData->paclreardefrost.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclreardefrostOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbcllefttempOpID: {
                    OpCBCLLeftTemp_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLLeftTemp_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->pacllefttemp.availability = ntohl(1);
                    notifyData->pacllefttemp.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclrighttempOpID: {
                    OpCBCLRightTemp_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLRightTemp_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclrighttemp.availability = ntohl(1);
                    notifyData->paclrighttemp.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclseclefttempOpID: {
                    OpCBCLSecLeftTemp_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLSecLeftTemp_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclseclefttemp.availability = ntohl(1);
                    notifyData->paclseclefttemp.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclsecrighttempOpID: {
                    OpCBCLSecRightTemp_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLSecRightTemp_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsecrighttemp.availability = ntohl(1);
                    notifyData->paclsecrighttemp.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclautoOpID: {
                    OpCBCLAuto_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLAuto_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclauto.availability = ntohl(1);
                    notifyData->paclauto.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclautoriOpID: {
                    OpCBCLAutoRi_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLAutoRi_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclautori.availability = ntohl(1);
                    notifyData->paclautori.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclsecautoswOpID: {
                    OpCBCLSecAutoSw_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLSecAutoSw_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsecautosw.availability = ntohl(1);
                    notifyData->paclsecautosw.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclsecautoswriOpID: {
                    OpCBCLSecAutoSwRi_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCBCLSecAutoSwRi_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsecautoswri.availability = ntohl(1);
                    notifyData->paclsecautoswri.data = data.value;
                    std::cout << "data.value = "
                              << data.value  << "  ntohl(data.value) = " <<  ntohl(data.value)
                              << std::endl;
                }
                    break;
                case cbclfanlevelOpID: {
                    OpCBCLFanLevel_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLFanLevel_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclfanlevel.availability = ntohl(1);
                    notifyData->paclfanlevel.data = data.value;
                    if(ntohl(data.value) <= 9){
                        notifyData->paclfanlevel.status = ntohl(0);
                    } else {
                        notifyData->paclfanlevel.status = ntohl(1);
                    }
                    common_log("syncToHal serviceID_CLIMATE cbclfanlevelOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclsecfanlevelOpID: {
                    OpCBCLSecFanLevel_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLSecFanLevel_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclsecfanlevel.availability = ntohl(1);
                    notifyData->paclsecfanlevel.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclsecfanlevelOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclrcircOpID: {
                    OpCBCLRcirc_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLRcirc_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclrecirc.availability = ntohl(1);
                    notifyData->paclrecirc.data = data.value;
                    if (ntohl(data.value) ==2){
                        needSyncToHal = false;
                    }
                    common_log("syncToHal serviceID_CLIMATE cbclrcircOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclmodefrstleftOpID: {
                    OpCBCLModeFrstLeft_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLModeFrstLeft_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclmodefrstleft.availability = ntohl(1);
                    notifyData->paclmodefrstleft.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclmodefrstleftOpID >>>>>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclmodesecOpID: {
                    OpCBCLModeSec_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLModeSec_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclmodesec.availability = ntohl(1);
                    notifyData->paclmodesec.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclmodesecOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclgcleanOpID: {
                    OpCBCLGClean_SetRequestNoReturn data;
                    constexpr int structLen = (int)sizeof(OpCBCLGClean_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclgclean.availability = ntohl(1);
                    notifyData->paclgclean.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclgcleanOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                case cbclventilationOpID: {
                    OpCBCLVentilation_SetRequestNoReturn  data;
                    constexpr int structLen = (int)sizeof(OpCBCLVentilation_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->paclventilation.availability = ntohl(1);
                    notifyData->paclventilation.data = data.value;
                    common_log("syncToHal serviceID_CLIMATE cbclventilationOpID >>>  set value:%d",ntohl(data.value));
                }
                    break;
                default:
                    needSyncToHal = false;
                    break;
            }
            if(needSyncToHal){
                memcpy(buffer, notifyData, sizeof(OpClimate_Notification));
                buf_len = sizeof(OpClimate_Notification);
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_VDDM: {
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_VDDM data is nullptr");
                return;
            }
            OpVDDM_Notification *notifyData = (OpVDDM_Notification *) data;
            switch (ipValue->oper_id) {
                case AutoHldSoftSwtCtrlStOpID: {
                    OpAutoHldSoftSwtCtrlSt_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpAutoHldSoftSwtCtrlSt_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->autHldSoftSwtEnaSts = data.value;

                    common_log(
                            "syncToHal serviceID_VDDM AutoHldSoftSwtCtrlStOpID >>>>>>  autHldSoftSwtEnaSts:%d",
                            static_cast<int>(data.value));
                    break;
                }
                case EPedlModCtrlStOpID: {
                    OpEPedlModCtrlSt_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpEPedlModCtrlSt_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 1) {//打开
                        notifyData->ePedlModSts = 3;
                    } else {
                        notifyData->ePedlModSts = 1;
                    }
                    common_log(
                            "syncToHal serviceID_VDDM EPedlModCtrlStOpID >>>>>>  ePedlModSts:%d",
                            static_cast<int>(data.value));
                    break;
                }
                    break;
                case EgyRgnLvlSetOpID:{
                    OpEgyRgnLvlSet_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpEgyRgnLvlSet_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->egyRgnLvlAct = data.value;

                    common_log(
                            "syncToHal serviceID_VDDM EgyRgnLvlSetOpID >>>>>>  egyRgnLvlAct:%d",
                            static_cast<int>(data.value));
                    break;
                }
                case V2XDchaSwtOpID: {
                    //放电-放电开关
                    OpV2XDchaSwt_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpV2XDchaSwt_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->v2XDchaSwtFb1 = data.value;
                    common_log(
                            "syncToHal serviceID_VDDM V2XDchaSwtOpID >>>>>>  v2XDchaSwtFb1:%d",
                            static_cast<int>(data.value));
                    break;
                }
                case DchaChrgnTarValOpID: {
                    //放电-放电设置SOC
                    OpDchaChrgnTarVal_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpDchaChrgnTarVal_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->dchaChrgnTarValFb = data.value;
                    common_log(
                            "syncToHal serviceID_VDDM DchaChrgnTarValOpID >>>>>>  dchaChrgnTarValFb:%d",
                            static_cast<int>(data.value));
                    break;
                }
                case MaxAcInpCurrentSetOpID: {
                    // 充电电流设置
                    OpMaxAcInpCurrentSet_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpMaxAcInpCurrentSet_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->maxACInpISetFdb = data.value;

                    common_log("syncToHal serviceID_VDDM MaxAcInpCurrentSetOpID >>>>>>  maxACInpISetFdb: %d", data.value);
                }
                    break;
                case ChgPreSetTempButtonReqOpID: {
                    // 在途热键按钮
                    OpChgPreSetTempButtonReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpChgPreSetTempButtonReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->chgPreSetTempButtonFb = data.value;
                    notifyData->hvBattTempSts = data.value;
                    notifyData->chgPreSetTempButtonInhibit = 1;

                    common_log("syncToHal serviceID_VDDM MaxAcInpCurrentSetOpID >>>>>>  chgPreSetTempButtonFb&hvBattTempSts: %d", data.value);
                }
                    break;
                default:
                    needSyncToHal = false;
                    break;
            }
            if (needSyncToHal) {
                memcpy(buffer, notifyData, sizeof(OpVDDM_Notification));
                buf_len = sizeof(OpVDDM_Notification);
            }
            break;
        }
        case EcarXSignalServiceID::serviceID_CARCONFIG:
        {
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_CARCONFIG data is nullptr");
                return;
            }
            memcpy(buffer, data, sizeof(OpCARCONFIG_Notification));
            buf_len = sizeof(OpCARCONFIG_Notification);
            common_log("syncToHal serviceID_CARCONFIG ");
        }
            break;
		case EcarXSignalServiceID::serviceID_CARCONFIGTHOUSAND:{
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal CARCONFIGTHOUSAND data is nullptr");
                return;
            }
            memcpy(buffer, data, sizeof(OpCARCONFIGTHOUSAND_Notification));
            buf_len = sizeof(OpCARCONFIGTHOUSAND_Notification);
            common_log("syncToHal CARCONFIGTHOUSAND");
        }
            break;

        case EcarXSignalServiceID::serviceID_CEM:{
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_CEM data is nullptr");
                return;
            }
            OpCEM_Notification *notifyData = (OpCEM_Notification *) data;
            bool useOtherNotifyData = false;
            switch (ipValue->oper_id) {
                //方向盘加热
                case SteerWhlHeatgOnReqOpID: {
                    OpSteerWhlHeatgOnReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpSteerWhlHeatgOnReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->steerWhlHeatgLvlSts = data.value ;
                    common_log("syncToHal serviceID_CEM SteerWhlHeatgOnReqOpID >>>  value:%d",data.value);
                }
                    break;
                // 电动尾门开关
                case TrunkOpenHmiReqOpID:
                {
                    OpTrunkOpenHmiReq_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpTrunkOpenHmiReq_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value;

                    if (da == 1) {
                        notifyData->trOpenerSts = 5;
                    } else if (da == 2) {
                        notifyData->trOpenerSts = 1;
                    } else if (da == 3) {
                        notifyData->trOpenerSts = 4;

                    }
                    std::cout << "TrunkOpenHmiReqOpID >>>>>> TrunkOpenHmiReq = " << da << std::endl;
                    common_log("syncToHal serviceID_CEM TrunkOpenHmiReqOpID >>>>>> TrunkOpenHmiReq  data:%d", da);
                }
                break;
                // 电动尾门位置选择
                case TopPosTrFromHmiOpID:
                {
                    OpTopPosTrFromHmi_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpTopPosTrFromHmi_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value;

                    if (da == 1) {
                        notifyData->topPosHmiFeedBack = 2;
                    } else if (da ==  2) {
                        notifyData->topPosHmiFeedBack = 3;
                    } else if (da == 3) {
                        notifyData->topPosHmiFeedBack = 4;
                    } else if (da == 4) {
                        notifyData->topPosHmiFeedBack = 5;
                    } else if (da == 5) {
                        notifyData->topPosHmiFeedBack = 6;
                    }
                    std::cout << "TopPosTrFromHmiOpID >>>>>> TopPosTrFromHmi = " << da << std::endl;
                    common_log("syncToHal serviceID_CEM TopPosTrFromHmiOpID >>>>>> TopPosTrFromHmi data:%d", da);
                }
                    break;
                // 电动尾门最大可开高度百分比设置
                case TopPercTrFromHmiOpID:
                {
                    OpTopPercTrFromHmi_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpTopPercTrFromHmi_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value;
                    notifyData->topPosHmiFeedBack2 = da;
                    std::cout << "TopPercTrFromHmiOpID >>>>>> TopPercTrFromHmi = " << da << std::endl;
                    common_log("syncToHal serviceID_CEM TopPercTrFromHmiOpID >>>>>> TopPercTrFromHmi data:%d", da);
                }
                    break;

                case FogSetRearReqOpID:
                    {
                        _OpFogSetRearReq_SetRequestNoReturn data;
                        constexpr int structLen=(int)sizeof(_OpFogSetRearReq_SetRequestNoReturn);
                        int bufferLength=structLen;
                        if (ipValue->payload_len < structLen) {
                            bufferLength = ipValue->payload_len;
                        }
                        memcpy(&data, ipValue->payload, bufferLength);
                        uint8_t da = data.value;
                        notifyData->extrLtgStsReFog = da;
                        std::cout << "FogSetReReqOpID FogSetReReq received value: " << static_cast<int>(da) << std::endl;
                        common_log("FogSetReReq: value:%d", static_cast<int>(da));
                    }
                    break;
                    // 空调 ECO 开关
                case HMIClimaEgySaveReqOpID:
                {
                    OpHMIClimaEgySaveReq_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpHMIClimaEgySaveReq_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value;
                    notifyData->ecoClimaSts = da;
                    std::cout << "HMIClimaEgySaveReqOpID >>>>>> HMIClimaEgySaveReq = " << static_cast<int>(da) << std::endl;
                    common_log("syncToHal serviceID_VGM HMIClimaEgySaveReqOpID >>>>>>  HMIClimaEgySaveReq:%d", static_cast<int>(da));
                }
                    break;
                // 阅读灯总开关
                case AllRoofLiSwtFromHmiOpID:
                {
                    OpAllRoofLiSwtFromHmi_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpAllRoofLiSwtFromHmi_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value == 1 ? 1 : 0;
                    notifyData->readLiStsFirstRowLe = da;
                    notifyData->readLiStsFirstRowRi = da;
                    notifyData->readLiStsSecondRowLe = da;
                    notifyData->readLiStsSecondRowRi = da;
                    common_log("syncToHal serviceID_CEM AllRoofLiSwtFromHmiOpID >>>>>>  AllRoofLiSwtFromHmi:%d", static_cast<int>(da));
                }
                    break;
                // 阅读灯单个开关
                case ReadLiOpenReqOpID:
                {
                    OpReadLiOpenReq_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpReadLiOpenReq_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->readLiStsFirstRowLe = data.readLiOpenReqFrontLeft == 1 ? 1 : 0;
                    notifyData->readLiStsFirstRowRi = data.readLiOpenReqFrontRight == 1 ? 1 : 0;
                    notifyData->readLiStsSecondRowLe = data.readLiOpenReqSecondRowLeft == 1 ? 1 : 0;
                    notifyData->readLiStsSecondRowRi = data.readLiOpenReqSecondRowRight == 1 ? 1 : 0;
                    common_log("syncToHal serviceID_CEM ReadLiOpenReqOpID >>>>>>  ReadLiOpenReq:%d, row1Le[%d], row1Ri[%d], row2Le[%d], row2Ri[%d]",
                            data.readLiOpenReqFrontLeft, data.readLiOpenReqFrontRight, data.readLiOpenReqSecondRowLeft, data.readLiOpenReqSecondRowRight);
                }
                    break;
                // 座椅加热、通风档位设置
                case HmiSeatClimaOpID:
                {
                    OpHmiSeatClima_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpHmiSeatClima_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    notifyData->drvrSeatHeatgLvlSts = data.hmiSeatClimaHmiSeatHeatgForRowFirstLe;
                    notifyData->passSeatHeatgLvlSts = data.hmiSeatClimaHmiSeatHeatgForRowFirstRi;
                    notifyData->seatHeatgLvlStsRowSecLe = data.hmiSeatClimaHmiSeatHeatgForRowSecLe;
                    notifyData->seatHeatgLvlStsRowSecRi = data.hmiSeatClimaHmiSeatHeatgForRowSecRi;

                    notifyData->drvrSeatVentnLvlSts = data.hmiSeatClimaHmiSeatVentnForRowFirstLe;
                    notifyData->passSeatVentnLvlSts = data.hmiSeatClimaHmiSeatVentnForRowFirstRi;
                    notifyData->seatVentnLvlStsRowSecLe = data.hmiSeatClimaHmiSeatVentnForRowSecLe;
                    notifyData->seatVentnLvlStsRowSecRi = data.hmiSeatClimaHmiSeatVentnForRowSecRi;
                    common_log("syncToHal serviceID_CEM HmiSeatClimaOpID >>>>>>  hrow1Le[%d], hrow1Ri[%d], hrow2Le[%d], hrow2Ri[%d], vrow1Le[%d], vrow1Ri[%d], vrow2Le[%d], vrow2Ri[%d]",
                            data.hmiSeatClimaHmiSeatHeatgForRowFirstLe, data.hmiSeatClimaHmiSeatHeatgForRowFirstRi, data.hmiSeatClimaHmiSeatHeatgForRowSecLe, data.hmiSeatClimaHmiSeatHeatgForRowSecRi,
                            data.hmiSeatClimaHmiSeatVentnForRowFirstLe, data.hmiSeatClimaHmiSeatVentnForRowFirstRi, data.hmiSeatClimaHmiSeatVentnForRowSecLe, data.hmiSeatClimaHmiSeatVentnForRowSecRi);
                }
                    break;
                 //童锁 left
                case ChdLockReLeCtrlHmiReqOpID: {
                    OpChdLockReLeCtrlHmiReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpChdLockReLeCtrlHmiReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 1) {
                        notifyData->chdPrtnLeftStsToHmi = 2;
                    } else if (data.value == 2) {
                        notifyData->chdPrtnLeftStsToHmi = 1;
                    }
                    std::cout << "ChdLockReLeCtrlHmiReqOpID >>>>>> chdPrtnLeftStsToHmi = "
                              << static_cast<int>(data.value) << std::endl;
                    common_log("syncToHal serviceID_CEM ChdLockReLeCtrlHmiReqOpID >>>>>>  chdPrtnLeftStsToHmi:%d",
                            static_cast<int>(data.value));
                }
                break;
                 //童锁 right
                case ChdLockReRiCtrlHmiReqOpID: {
                    OpChdLockReRiCtrlHmiReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpChdLockReRiCtrlHmiReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 1) {
                        notifyData->chdLockRightStsToHmi = 2;
                    } else if (data.value == 2) {
                        notifyData->chdLockRightStsToHmi = 1;
                    }
                    std::cout << "ChdLockReRiCtrlHmiReqOpID >>>>>> chdLockRightStsToHmi = "
                              << static_cast<int>(data.value) << std::endl;
                    common_log( "syncToHal serviceID_CEM ChdLockReRiCtrlHmiReqOpID >>>>>>  chdLockRightStsToHmi:%d",
                            static_cast<int>(data.value));
                }
                break;
                    //驾驶舱过热
                case CbnOverHeatProtnEnaOpID: {
                    OpCbnOverHeatProtnEna_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpCbnOverHeatProtnEna_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    uint8_t da = data.value;
                    notifyData->climaOvrHeatProActvSts = da;
                    std::cout << "CbnOverHeatProtnEnaOpID OverHeatProtnEna received value: " << static_cast<int>(da) << std::endl;
                    common_log("climaOvrHeatProActvSts: value:%d", static_cast<int>(da));
                }
                    break;
                    // 主驾 第一排座椅侧翼支撑 前后调节
                case BackRestSideSpprtAdjmtRowFirstDrvrOpID: {
                    useOtherNotifyData = true;
                    void *cdmData;
                    int cdmSvcId = 36;
                    notifyDataMap.Find(cdmSvcId, cdmData);
                    if (cdmData == nullptr) {
                        common_log("syncToHal serviceID_CDM data is nullptr");
                        return;
                    }
                    OpCDM_Notification *cdmNotifyData = (OpCDM_Notification *) cdmData;
                    common_log("syncToHal CDM code:%d", ipValue->oper_id);

                    cdmNotifyData->drvrSeatActvSpplFct = 2;
                    cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpBackRestSideSpprtAdjmtRowFirstDrvr_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpBackRestSideSpprtAdjmtRowFirstDrvr_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    memcpy(&data, ipValue->payload, static_cast<size_t>(bufferLength));

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 1;
                    } else if (value == 2) {
                        cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 2;
                    }

                    ipValue->service_id = static_cast<uint16_t>(cdmSvcId);
                    ipValue->oper_id = 999;
                    memcpy(buffer, cdmNotifyData, sizeof(OpCDM_Notification));
                    buf_len = sizeof(OpCDM_Notification);
                }
                    break;
                    // 副驾 第一排座椅侧翼支撑 前后调节
                case BackRestSideSpprtAdjmtRowFirstPassOpID: {
                    useOtherNotifyData = true;
                    void *cdmData;
                    int cdmSvcId = 36;
                    notifyDataMap.Find(cdmSvcId, cdmData);
                    if (cdmData == nullptr) {
                        common_log("syncToHal serviceID_CDM data is nullptr");
                        return;
                    }
                    OpCDM_Notification *cdmNotifyData = (OpCDM_Notification *) cdmData;
                    common_log("syncToHal CDM code:%d", ipValue->oper_id);

                    cdmNotifyData->passSeatActvSpplFct = 2;
                    cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpBackRestSideSpprtAdjmtRowFirstPass_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpBackRestSideSpprtAdjmtRowFirstPass_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    ipValue->service_id = static_cast<uint16_t>(cdmSvcId);
                    ipValue->oper_id = 999;
                    memcpy(&data, ipValue->payload, static_cast<size_t>(bufferLength));

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 1;
                    } else if (value == 2) {
                        cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 2;
                    }

                    memcpy(buffer, cdmNotifyData, sizeof(OpCDM_Notification));
                    buf_len = sizeof(OpCDM_Notification);
                }
                    break;
                    // 主驾 第一排座椅侧翼支撑 上下调节
                case CushSideSpprtAdjmtRowFirstDrvrOpID: {
                    useOtherNotifyData = true;
                    void *cdmData;
                    int cdmSvcId = 36;
                    notifyDataMap.Find(cdmSvcId, cdmData);
                    if (cdmData == nullptr) {
                        common_log("syncToHal serviceID_CDM data is nullptr");
                        return;
                    }
                    OpCDM_Notification *cdmNotifyData = (OpCDM_Notification *) cdmData;
                    common_log("syncToHal CDM code:%d", ipValue->oper_id);

                    cdmNotifyData->drvrSeatActvSpplFct = 2;
                    cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 0;

                    OpCushSideSpprtAdjmtRowFirstDrvr_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCushSideSpprtAdjmtRowFirstDrvr_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    memcpy(&data, ipValue->payload, static_cast<size_t>(bufferLength));

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 1;
                    } else if (value == 2) {
                        cdmNotifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 2;
                    }

                    ipValue->service_id = static_cast<uint16_t>(cdmSvcId);
                    ipValue->oper_id = 999;
                    memcpy(buffer, cdmNotifyData, sizeof(OpCDM_Notification));
                    buf_len = sizeof(OpCDM_Notification);
                }
                    break;
                    // 副驾 第一排座椅侧翼支撑 上下调节
                case CushSideSpprtAdjmtRowFirstPassOpID: {
                    useOtherNotifyData = true;
                    void *cdmData;
                    int cdmSvcId = 36;
                    notifyDataMap.Find(cdmSvcId, cdmData);
                    if (cdmData == nullptr) {
                        common_log("syncToHal serviceID_CDM data is nullptr");
                        return;
                    }
                    OpCDM_Notification *cdmNotifyData = (OpCDM_Notification *) cdmData;
                    common_log("syncToHal CDM code:%d", ipValue->oper_id);

                    cdmNotifyData->passSeatActvSpplFct = 2;
                    cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 0;

                    OpCushSideSpprtAdjmtRowFirstPass_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCushSideSpprtAdjmtRowFirstPass_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    memcpy(&data, ipValue->payload, static_cast<size_t>(bufferLength));

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 1;
                    } else if (value == 2) {
                        cdmNotifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 2;
                    }

                    ipValue->service_id = static_cast<uint16_t>(cdmSvcId);
                    ipValue->oper_id = 999;
                    memcpy(buffer, cdmNotifyData, sizeof(OpCDM_Notification));
                    buf_len = sizeof(OpCDM_Notification);
                }
                    break;
                 //前机舱盖设置
                case HoodUnlckHmiReqOpID: {
                    _OpHoodUnlckHmiReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(_OpHoodUnlckHmiReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 1) {
                        notifyData->hoodSts1 = 1;
                    }
                    std::cout << "HoodUnlckHmiReqOpID >>>>>> hoodUnlckHmiReq = "
                              << static_cast<int>(data.value) << std::endl;
                    common_log( "syncToHal serviceID_CEM HoodUnlckHmiReqOpID >>>>>>  hoodUnlckHmiReq:%d",
                            static_cast<int>(data.value));
                }
                break;
                 //中央锁
                case CenLockHmiReqOpID: {
                    _OpCenLockHmiReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(_OpCenLockHmiReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 1) {
                        notifyData->lockgCenStsLockSt = 1;
                    }else if(data.value == 2){
                        notifyData->lockgCenStsLockSt = 3;
                    }
                    std::cout << "HoodUnlckHmiReqOpID >>>>>> hoodUnlckHmiReq = "
                              << static_cast<int>(data.value) << std::endl;
                    common_log( "syncToHal serviceID_CEM HoodUnlckHmiReqOpID >>>>>>  hoodUnlckHmiReq:%d",
                            static_cast<int>(data.value));
                }
                break;
                    //找车提醒
                case CarFindrHornLiSetActvOpID: {
                    OpCarFindrHornLiSetActv_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpCarFindrHornLiSetActv_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.value == 3) {
                        notifyData->carLoctrHornLiSetActv = 0;
                    } else if (data.value == 1) {
                        notifyData->carLoctrHornLiSetActv = 1;
                    } else if (data.value == 2) {
                        notifyData->carLoctrHornLiSetActv = 2;
                    }

                    common_log(
                            "syncToHal serviceID_CEM SETTING_FUNC_CAR_LOCATOR_REMINDER_MODE CarFindrHornLiSetActvOpID >>>>>>  carLoctrHornLiSetActv:%d",
                            static_cast<int>(notifyData->carLoctrHornLiSetActv));

                }
                    break;
                    //充电盖开关
                case ChrgLidCtrlHmiReqOpID: {
                    _OpChrgLidCtrlHmiReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(_OpChrgLidCtrlHmiReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->chrgLidAcSts = data.chrgLidCtrlHmiReqACchargelid;
                    notifyData->chrgLidDCorAcDcSts = data.chrgLidCtrlHmiReqDCchargelid;
                    if(data.chrgLidCtrlHmiReqACchargelid == 1 && data.chrgLidCtrlHmiReqACandDCchargelid == 1){
                        notifyData->chrgLidDCorAcDcSts = 1;
                    }else if(data.chrgLidCtrlHmiReqACchargelid == 1 && data.chrgLidCtrlHmiReqACandDCchargelid == 2){
                        notifyData->chrgLidDCorAcDcSts = 2;
                    }
                    common_log( "syncToHal serviceID_CEM ChrgLidCtrlHmiReqOpID >>>>>>  ac:[%d],dc:[%d],acdc:[%d]"
                                ,static_cast<int>(data.chrgLidCtrlHmiReqACchargelid)
                                ,static_cast<int>(data.chrgLidCtrlHmiReqDCchargelid)
                                ,static_cast<int>(data.chrgLidCtrlHmiReqACandDCchargelid));
                }
                    break;
                    //后尾门实时位置
                case TrOpenPosnReqFromHmiOpID: {
                    OpTrOpenPosnReqFromHmi_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpTrOpenPosnReqFromHmi_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    notifyData->trOpenPosn = data.value;
                    common_log( "syncToHal serviceID_CEM TrOpenPosnReqFromHmiOpID >>>>>>  value:[%d]"
                            ,static_cast<int>(data.value));
                }
                    break;
                default:
                    needSyncToHal = false;
                    break;
            }
            if(!useOtherNotifyData && needSyncToHal) {
                memcpy(buffer, notifyData, sizeof(_OpCEM_Notification));
                buf_len = sizeof(_OpCEM_Notification);
            }
        }
            break;

        case EcarXSignalServiceID::serviceID_CDM:{
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_CDM data is nullptr");
                return;
            }
            OpCDM_Notification *notifyData = (OpCDM_Notification *) data;
            common_log("syncToHal CDM code:%d", ipValue->oper_id);
            switch (ipValue->oper_id) {
                // 主驾菜单 设置
                case DrvrSeatDispSpplFctOpID: {
                    notifyData->drvrSeatActvSpplFct = 0;
                    notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpDrvrSeatDispSpplFct_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpDrvrSeatDispSpplFct_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value > 0 && value < 6) {
                        notifyData->drvrSeatActvSpplFct = value;
                    }
                }
                    break;
                // 副驾菜单 设置
                case PassSeatDispSpplFctOpID: {
                    notifyData->passSeatActvSpplFct = 0;
                    notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpPassSeatDispSpplFct_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpPassSeatDispSpplFct_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value > 0 && value < 6) {
                        notifyData->passSeatActvSpplFct = value;
                    }
                }
                    break;
                // 主驾腰托 前后调节
                case LumLenAdjmtRowFirstDrvrOpID:
                {
                    notifyData->drvrSeatActvSpplFct = 1;
                    notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpLumLenAdjmtRowFirstDrvr_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpLumLenAdjmtRowFirstDrvr_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 1;
                    } else if (value ==  2) {
                        notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctHozlSts = 2;
                    }
                }
                    break;
                    // 主驾腰托 上下调节
                case LumHeiAdjmtRowFirstDrvrOpID:
                {
                    notifyData->drvrSeatActvSpplFct = 1;
                    notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 0;

                    OpLumHeiAdjmtRowFirstDrvr_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpLumHeiAdjmtRowFirstDrvr_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 1;
                    } else if (value ==  2) {
                        notifyData->drvrSeatSwtStsDrvrSeatSwtAdjmtOfSpplFctVertSts = 2;
                    }
                }
                    break;
                    // 副驾腰托 前后调节
                case LumLenAdjmtRowFirstPassOpID:
                {
                    notifyData->passSeatActvSpplFct = 1;
                    notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 0;

                    OpLumLenAdjmtRowFirstPass_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpLumLenAdjmtRowFirstPass_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 1;
                    } else if (value ==  2) {
                        notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctHozlSts = 2;
                    }
                }
                    break;
                    // 副驾腰托 上下调节
                case LumHeiAdjmtRowFirstPassOpID:
                {
                    notifyData->passSeatActvSpplFct = 1;
                    notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 0;

                    OpLumHeiAdjmtRowFirstPass_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpLumHeiAdjmtRowFirstPass_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 1;
                    } else if (value ==  2) {
                        notifyData->passSeatSwtSts2PassSeatSwtAdjmtOfSpplFctVerSts = 2;
                    }
                }
                    break;
                //Two Step unlock 两步解锁模式设置
                case UnlckRemReqOpID:{
                    needSyncToHal = false;

                    OpUnlckRemReq_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(OpUnlckRemReq_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    std::cout << "UnlckRemReqOpID >>>>>> unlckRemReqPen = " << static_cast<int>(data.unlckRemReqPen)
                              <<  ", unlckRemReqAllOrDriving = " << static_cast<int>(data.unlckRemReqAllOrDriving) << std::endl;
                    common_log("syncToHal serviceID_VGM UnlckRemReqOpID >>>>>>  unlckRemReqPen:%d, unlckRemReqAllOrDriving:%d", static_cast<int>(data.unlckRemReqPen), static_cast<int>(data.unlckRemReqAllOrDriving));

                }
                    break;

                    //遮阳帘位置
                case SunCurtOpenPosnReqOpID: {
                    OpSunCurtOpenPosnReq_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpSunCurtOpenPosnReq_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);

                    notifyData->sunCurtPosnSts = data.value;
                    notifyData->sunCurtMvngSts = 0;//触发正在移动中停止
                    std::cout << "SunCurtOpenPosnReqOpID >>>>>> sunCurtPosnSts = "
                              << static_cast<int>(data.value) << std::endl;
                    common_log( "syncToHal serviceID_VGM SunCurtOpenPosnReqOpID sunCurtMvngSts>>> 0 >>>>>>  sunCurtPosnSts:%d",
                                static_cast<int>(data.value));
                }
                    break;
                    // AR脚踢后尾门功能开关
                case ARFootKickTrSettngOpID:
                {
                    _OpARFootKickTrSettng_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(_OpARFootKickTrSettng_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->aRFootKickTrSetgSts = 1;
                    } else if (value ==  2) {
                        notifyData->aRFootKickTrSetgSts = 0;
                    }
                    std::cout << "ARFootKickTrSettngOpID >>>>>> value = " << static_cast<int>(value) << std::endl;
                    common_log("syncToHal serviceID_CDM ARFootKickTrSettngOpID >>>>>>  value:%d", static_cast<int>(value));

                }
                    break;
                    // 自动关窗开关
                case AutClsWinSetOpID:
                {
                    _OpAutClsWinSet_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(_OpAutClsWinSet_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    int value = static_cast<int>(data.value);
                    if (value == 1) {
                        notifyData->winClsAutEnaSts = 1;
                    } else if (value ==  2) {
                        notifyData->winClsAutEnaSts = 0;
                    }
                    std::cout << "AutClsWinSetOpID >>>>>> value = " << static_cast<int>(value) << std::endl;
                    common_log("syncToHal serviceID_CDM AutClsWinSetOpID >>>>>>  value:%d", static_cast<int>(value));

                }
                    break;
                case ExtrMirrFoldSetgOpID:
                {
                    OpExtrMirrFoldSetg_SetRequestNoReturn data;
                    constexpr int structLen=(int)sizeof(_OpExtrMirrFoldSetg_SetRequestNoReturn);
                    int bufferLength=structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = ipValue->payload_len;
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    int value = static_cast<int>(data.value);
                    switch (value)
                    {
                    case 1:
                        notifyData->extrMirrFoldSetSts = 0;
                        break;
                    case 2:
                        notifyData->extrMirrFoldSetSts = 1;
                        break;
                    case 3:
                        notifyData->extrMirrFoldSetSts = 2;
                        break;
                    default:
                        notifyData->extrMirrFoldSetSts = 0;
                        break;
                    }
                    std::cout << "ExtrMirrFoldSetgOpID >>>>>> value = " << static_cast<int>(value) << std::endl;
                    common_log("syncToHal serviceID_CDM ExtrMirrFoldSetgOpID >>>>>>  value:%d", static_cast<int>(value));

                }
                    break;
                default:
                    needSyncToHal = false;
                    break;
            }
            if(needSyncToHal) {
                memcpy(buffer, notifyData, sizeof(_OpCDM_Notification));
                buf_len = sizeof(_OpCDM_Notification);
            }
        }
            break;
        case EcarXSignalServiceID::serviceID_ASDM: {
            void *data;
            notifyDataMap.Find(ipValue->service_id, data);
            if (data == nullptr) {
                common_log("syncToHal serviceID_ASDM data is nullptr");
                return;
            }
            OpASDM_Notification *notifyData = (OpASDM_Notification *) data;
            common_log("syncToHal ASDM code:%d", ipValue->oper_id);
            switch (ipValue->oper_id) {
                // 驾驶员疲劳检测DPS
                case DrvrPfmncMonActvStsOpID: {
                    OpDrvrPfmncMonActvSts_SetRequestNoReturn data;
                    constexpr int structLen = (int) sizeof(OpDrvrPfmncMonActvSts_SetRequestNoReturn);
                    int bufferLength = structLen;
                    if (ipValue->payload_len < structLen) {
                        bufferLength = static_cast<int>(ipValue->payload_len);
                    }
                    memcpy(&data, ipValue->payload, bufferLength);
                    if (data.drvrPfmncMonActvStsOnOff1 == 1) {
                        notifyData->drvrPfmncSwitchSts = 2;
                    } else if (data.drvrPfmncMonActvStsOnOff1 == 0) {
                        notifyData->drvrPfmncSwitchSts = 2;
                    }
                    std::cout << "DrvrPfmncMonActvStsOpID >>>>>> data.drvrPfmncMonActvStsOnOff1 = "
                              << static_cast<int>(data.drvrPfmncMonActvStsOnOff1) << std::endl;
                    common_log(
                            "syncToHal serviceID_CEM DrvrPfmncMonActvStsOpID >>>>>>  data.drvrPfmncMonActvStsOnOff1:%d",
                            static_cast<int>(data.drvrPfmncMonActvStsOnOff1));
                }
                    break;
                default:
                    needSyncToHal = false;
                    break;
            }

            if (needSyncToHal) {
                memcpy(buffer, notifyData, sizeof(_OpASDM_Notification));
                buf_len = sizeof(_OpCDM_Notification);
            }
        }
            break;
        default:
            needSyncToHal = false;
            break;
    }
    if (!needSyncToHal) {
        std::cout<<"no syncToHal required" << "\n";
        common_log("syncToHal no syncToHal required");
        return;
    }
    ipcp_packet_t *packet = build_ipcp_packet(ipValue->service_id, ipValue->oper_id,
                                              IPCP_OPERATION_NOTIFICATION, ipValue->payload_type,
                                              buffer, buf_len);
    ipcp_stack_err_t error_code = ipcp_send(udp_hal_peer, packet);
    std::cout<<"syncToHal, result code: " << error_code << "\n";
    common_log("syncToHal result code:%d", error_code);
}

void error_cb(ipcp_packet_t *ipcp_packet, ipcp_stack_err_t error) {
    std::cout << "error_cb   operation_id:" << ipcp_packet->header.operation_id << "--service_id:"
              << ipcp_packet->header.service_id << "error:" << error << "\n";
}

void initNotifyDataMap(int serviceId) {
    switch (serviceId)
    {
        case EcarXSignalServiceID::serviceID_VGM:
        {
            OpVGM_Notification* notifyData = (OpVGM_Notification*)malloc(sizeof(OpVGM_Notification));
            memset(notifyData, 0, sizeof(OpVGM_Notification));
            notifyDataMap.Insert(serviceId,  notifyData);
        }
            break;
        case EcarXSignalServiceID::serviceID_CLIMATE: {
            OpClimate_Notification* notifyData = (OpClimate_Notification*)malloc(sizeof(OpClimate_Notification));
            memset(notifyData, 0, sizeof(OpClimate_Notification));
            notifyDataMap.Insert(serviceId, notifyData);
        }
            break;
        case EcarXSignalServiceID::serviceID_VDDM:
        {
            OpVDDM_Notification* notifyData = (OpVDDM_Notification*)malloc(sizeof(OpVDDM_Notification));
            memset(notifyData, 0, sizeof(OpVDDM_Notification));
            notifyDataMap.Insert(serviceId,  notifyData);
            break;
        }
        case EcarXSignalServiceID::serviceID_CARCONFIG:
        {
            int lenData = sizeof(OpCARCONFIG_Notification);
            OpCARCONFIG_Notification* data = (OpCARCONFIG_Notification*)malloc(lenData);
            memset(data, 0, lenData);
            notifyDataMap.Insert(serviceId,  data);
            break;
        }
        case EcarXSignalServiceID::serviceID_CARCONFIGTHOUSAND:
        {
            int lenData = sizeof(OpCARCONFIGTHOUSAND_Notification);
            OpCARCONFIGTHOUSAND_Notification* data =(OpCARCONFIGTHOUSAND_Notification*)malloc(lenData);
            memset(data, 0, lenData);
            notifyDataMap.Insert(serviceId,  data);
            break;
        }
        case EcarXSignalServiceID::serviceID_CEM:
        {
            OpCEM_Notification* notifyData = (OpCEM_Notification*)malloc(sizeof(OpCEM_Notification));
            memset(notifyData, 0, sizeof(OpCEM_Notification));
            notifyDataMap.Insert(serviceId,  notifyData);
        }
            break;
        case EcarXSignalServiceID::serviceID_CDM:
        {
            OpCDM_Notification * notifyData = (OpCDM_Notification*)malloc(sizeof(OpCDM_Notification));
            memset(notifyData, 0, sizeof(OpCDM_Notification));
            notifyDataMap.Insert(serviceId,  notifyData);
        }
            break;
        case EcarXSignalServiceID::serviceID_ASDM: {
            OpASDM_Notification *notifyData = (OpASDM_Notification *) malloc(sizeof(OpASDM_Notification));
            memset(notifyData, 0, sizeof(OpASDM_Notification));
            notifyDataMap.Insert(serviceId, notifyData);
        }
            break;
        default:
            break;
    }
}

int main() {
    printf("#1 start IPCP Server STACK\n");
    set_log_tag("MockServer");
    mBatchingConsumer.run(&mIpcpQueue, &readThread);

    for (int id = MIN_SIGNAL_SERVICE_ID; id < MAX_CUSTOM_SERVICE_ID; id++) {
        if (ecarx::transfer::validate::availableServiceID(id)) {
            mTransportConfigs.emplace_back(
                    ipcp_transport_conf_t{.service_id = static_cast<uint16_t>(id),
                            .host_ip = LOCAL_SERVER_IP,
                            .host_port = LOCAL_SERVER_PORT,
                            .sk_type = IPCP_TRANSPORT_UDP,
                            .vlan = 6,
                            .priority = 6});
        }
    }
    //添加仪表接收服务（仪表分三个通信端口三个serviceID，
    // NORMAL: port=50600, serviceId=0x127
    // TIME:port=50601,serviceId=0x128
    // AVAS:port=50602,serviceId=0x129
    // 接收：port50435,）
    //添加仪表 NORMAL通信
    mTransportConfigsForDim.emplace_back(
            ipcp_transport_conf_t{.service_id = CP_serviceID_Normal,
                    .host_ip = LOCAL_SERVER_IP,
                    .host_port = CP_SERVICE_NORMAL_PORT,
                    .sk_type = IPCP_TRANSPORT_UDP,
                    .vlan = 6,
                    .priority = 6});
    //添加仪表 TIME通信
    mTransportConfigsForDim.emplace_back(
            ipcp_transport_conf_t{.service_id = CP_serviceID_TimeSync,
                    .host_ip = LOCAL_SERVER_IP,
                    .host_port = CP_SERVICE_TIME_PORT,
                    .sk_type = IPCP_TRANSPORT_UDP,
                    .vlan = 6,
                    .priority = 6});
    //添加仪表 AVAS通信
    mTransportConfigsForDim.emplace_back(
            ipcp_transport_conf_t{.service_id = CP_serviceID_AVAS,
                    .host_ip = LOCAL_SERVER_IP,
                    .host_port = CP_SERVICE_AVAS_PORT,
                    .sk_type = IPCP_TRANSPORT_UDP,
                    .vlan = 6,
                    .priority = 6});


    for (const ipcp_transport_conf_t conf : mTransportConfigsForDim) {
        ::ecarx::transfer::apcp::ValidOperationArray operIdsArray =
                ecarx::transfer::apcp::getValidOperationArray(conf.service_id);
        ipcp_stack_err_t error_code = ipcp_setup_with_opids(conf,  &callbacks, operIdsArray.oper_ids,
                                                            operIdsArray.len);

        std::cout<<"ipcp service_id: " << conf.service_id  << "--error_code: " << error_code <<"\n";
        std::cout<< "ipcp host_ip: " << conf.host_ip << " host_port: " << conf.host_port  <<"\n";
        if (error_code == 0) {
            for (int i = 0; i < operIdsArray.len; i++) {
                ipcp_set_wfa_retry_count(conf.service_id, operIdsArray.oper_ids[i], 0);
                ipcp_set_wfr_retry_count(conf.service_id, operIdsArray.oper_ids[i], 0);
                std::cout<< "service_id: " << conf.service_id <<  " len: " << operIdsArray.len <<" oper_id: " << operIdsArray.oper_ids[i]  <<"\n";
            }
        } else {
            std::cout << "ipcp_setup_with_opids failed, service_id: " << conf.service_id
                      << "--error_code: " << error_code << "\n";
        }
    }

    for (const ipcp_transport_conf_t conf : mTransportConfigs) {
                ::ecarx::transfer::validate::ValidOperationArray operIdsArray =
                    ecarx::transfer::validate::getValidOperation(conf.service_id);
        ipcp_stack_err_t error_code = ipcp_setup_with_opids(conf,  &callbacks, operIdsArray.oper_ids,
                                                   operIdsArray.len);

        std::cout<<"ipcp service_id: " << conf.service_id  << "--error_code: " << error_code <<"\n";
        std::cout<< "ipcp host_ip: " << conf.host_ip << " host_port: " << conf.host_port  <<"\n";
        if (error_code == 0) {
            for (int i = 0; i < operIdsArray.len; i++) {
                ipcp_set_wfa_retry_count(conf.service_id, operIdsArray.oper_ids[i], 0);
                ipcp_set_wfr_retry_count(conf.service_id, operIdsArray.oper_ids[i], 0);
                std::cout<< "service_id: " << conf.service_id <<  " len: " << operIdsArray.len <<" oper_id: " << operIdsArray.oper_ids[i]  <<"\n";
            }
            initNotifyDataMap(conf.service_id);
        } else {
            std::cout << "ipcp_setup_with_opids failed, service_id: " << conf.service_id
                      << "--error_code: " << error_code << "\n";
        }
    }

    std::cout << "开始等待。。。。" << "\n";
    while (true) {
        sleep(1);
    }
    mBatchingConsumer.requestStop();
    mIpcpQueue.deactivate();
    mBatchingConsumer.waitStopped();
    return 0;
}